﻿#include <QCoreApplication>
#include "ImageSaveToolBar.h"
#include <QDebug>
ImageSaveToolBar::ImageSaveToolBar(QWidget *parent)
    :QToolBar(parent)
{
    setWindowTitle(tr("Open And Save Image"));
    setIconSize(QSize(32, 32));

    m_pActionOpen[0] = new QAction(tr("Load image to CH 1"), this);
    m_pActionOpen[1] = new QAction(tr("Load image to CH 2"), this);
    m_pActionOpen[0]->setIcon(QIcon(":/res/open1.png"));
    m_pActionOpen[1]->setIcon(QIcon(":/res/open2.png"));
    addAction(m_pActionOpen[0]);
    addAction(m_pActionOpen[1]);
    connect(m_pActionOpen[0], &QAction::triggered, this, &ImageSaveToolBar::onAction);
    connect(m_pActionOpen[1], &QAction::triggered, this, &ImageSaveToolBar::onAction);

    addSeparator();

    m_pActionSave[0] = new QAction(tr("Save CH 1 image to file."), this);
    m_pActionSave[1] = new QAction(tr("Save CH 2 image to file."), this);
    addAction(m_pActionSave[0]);
    addAction(m_pActionSave[1]);
    m_pActionSave[0]->setIcon(QIcon(":/res/filesave1.png"));
    m_pActionSave[1]->setIcon(QIcon(":/res/filesave2.png"));
    addAction(m_pActionSave[0]);
    addAction(m_pActionSave[1]);
    connect(m_pActionSave[0], &QAction::triggered, this, &ImageSaveToolBar::onAction);
    connect(m_pActionSave[1], &QAction::triggered, this, &ImageSaveToolBar::onAction);
}

void ImageSaveToolBar::retranslateUi()
{
    m_pActionSave[0]->setText(QCoreApplication::translate("ImageSaveToolBar", "Save CH 1 image to file.", nullptr));
    m_pActionSave[1]->setText(QCoreApplication::translate("ImageSaveToolBar", "Save CH 2 image to file.", nullptr));
    m_pActionOpen[0]->setText(QCoreApplication::translate("ImageSaveToolBar", "Load image to CH 1.", nullptr));
    m_pActionOpen[1]->setText(QCoreApplication::translate("ImageSaveToolBar", "Load image to CH 2.", nullptr));
}

void ImageSaveToolBar::onAction(bool checked)
{
    Q_UNUSED(checked);
    QAction *pAction = (QAction *)sender();
    if(pAction == m_pActionSave[0])
    {
        emit saveImage(0);
        return;
    }
    if(pAction == m_pActionSave[1])
    {
        emit saveImage(1);
        return;
    }
    if(pAction == m_pActionOpen[0])
    {
        emit openFile(0);
        return;
    }
    if(pAction == m_pActionOpen[1])
    {
        emit openFile(1);
        return;
    }
}
